package com.frank.libandroid.util;

import android.text.InputType;
import android.text.method.HideReturnsTransformationMethod;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.widget.EditText;

public class PasswordVisibleUtil {
    public static void setPasswordVisible(EditText editText, View view) {
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (view.isSelected()) {
                    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                    editText.setTransformationMethod(PasswordTransformationMethod.getInstance()); // 隐藏密码
                } else {
                    editText.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD);
                    editText.setTransformationMethod(HideReturnsTransformationMethod.getInstance()); // 显示密码
                }
                view.setSelected(!view.isSelected());
            }
        });

    }
}
